package org.ben.arithmetic;

import java.util.Arrays;

public class QuickSort {
	public static void main(String[] args) {
		int[] a={5,8,6,9,2,1,4};
		quickSort(a,0,a.length-1);
		System.out.println(Arrays.toString(a));
	}
	
	public static void quickSort(int[] a,int low,int high) {
		if(high<=1) {
			return;
		}
		if (low < high) {
			int start = low;
			int end = high;
			int temp = a[low];
			while (start != end) {
				while (start < end && temp <= a[end]) {
					end--;
				}
				a[start] = a[end];
				while (start < end && a[start] <= temp) {
					start++;
				}
				a[end] = a[start];
				
				
			}
			a[start]=temp;
			quickSort(a, low, end);
			quickSort(a, start + 1, high);
		}
		
	}

}
